﻿#region Copyright
// Copyright (c) 2011-2012 RaisingForce Team (Alikin Sergey)
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using RaisingForce.Raise.Language.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace RaisingForce.Raise.Tests
{


    /// <summary>
    ///Это класс теста для GlyphPoolTest, в котором должны
    ///находиться все модульные тесты GlyphPoolTest
    ///</summary>
    [TestClass()]
    public class GlyphPoolTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Получает или устанавливает контекст теста, в котором предоставляются
        ///сведения о текущем тестовом запуске и обеспечивается его функциональность.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Дополнительные атрибуты теста
        // 
        //При написании тестов можно использовать следующие дополнительные атрибуты:
        //
        //ClassInitialize используется для выполнения кода до запуска первого теста в классе
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //ClassCleanup используется для выполнения кода после завершения работы всех тестов в классе
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //TestInitialize используется для выполнения кода перед запуском каждого теста
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //TestCleanup используется для выполнения кода после завершения каждого теста
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Тест для Конструктор GlyphPool
        ///</summary>
        [TestMethod()]
        public void GlyphPoolConstructorTest()
        {
            bool registerDefaultContainers = false;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            Assert.AreEqual(0, target.GlyphTypeCount);
            registerDefaultContainers = true;
            target = new GlyphPool(registerDefaultContainers);
            Assert.IsTrue(target.GlyphTypeCount > 0);
        }

        /// <summary>
        ///Тест для ContainsContainer
        ///</summary>
        [TestMethod()]
        public void ContainsContainerTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            IGlyphContainer glyphContainer = target[typeof(DirectionGlyph)];
            bool expected = true;
            bool actual;
            actual = target.ContainsContainer(glyphContainer);
            Assert.AreEqual(expected, actual);
            target.UnregisterContainer(glyphContainer);
            expected = false;
            actual = target.ContainsContainer(glyphContainer);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///Тест для ContainsType
        ///</summary>
        [TestMethod()]
        public void ContainsTypeTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            Type glyphType = typeof(ObjectGlyph);
            bool expected = true;
            bool actual;
            actual = target.ContainsType(glyphType);
            Assert.AreEqual(expected, actual);
            target.UnregisterContainer(target[typeof(ObjectGlyph)]);
            expected = false;
            actual = target.ContainsType(glyphType);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///Тест для ContainsTypeName
        ///</summary>
        [TestMethod()]
        public void ContainsTypeNameTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            string glyphTypeName = CounterGlyph.Name;
            bool expected = true;
            bool actual;
            actual = target.ContainsTypeName(glyphTypeName);
            Assert.AreEqual(expected, actual);
            target.UnregisterContainer(target[typeof(CounterGlyph)]);
            expected = false;
            actual = target.ContainsTypeName(glyphTypeName);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void GetContainerTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            IGlyphContainer<ChainGlyph> expected =
                (IGlyphContainer<ChainGlyph>)target[ChainGlyph.Name];
            IGlyphContainer<ChainGlyph> actual;
            actual = target.GetContainer<ChainGlyph>();
            Assert.AreSame(expected, actual);
        }

        /// <summary>
        ///Тест для GetEnumerator
        ///</summary>
        [TestMethod()]
        public void GetEnumeratorTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            IEnumerator<IGlyphContainer> actual;
            actual = target.GetEnumerator();
            foreach (IGlyphContainer container in target)
            {
                Assert.IsNotNull(container);
                Assert.IsTrue(target.ContainsContainer(container));
            }
        }

        [TestMethod()]
        public void GetGlyphTest()
        {
            // Direction Glyph
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            string value = DirectionType.Left.ToString();
            DirectionGlyph actualDirection;
            actualDirection = target.GetGlyph<DirectionGlyph>(value);
            Assert.IsNotNull(actualDirection);
            Assert.AreEqual(DirectionGlyph.Name, actualDirection.TypeName);
            Assert.AreEqual(DirectionType.Left, actualDirection.Value);
            // Chain Glyph
            value = "B";
            ChainGlyph actualChain = target.GetGlyph<ChainGlyph>(value);
            Assert.IsNotNull(actualDirection);
            Assert.AreEqual(ChainGlyph.Name, actualChain.TypeName);
            Assert.AreEqual(value, actualChain.Value);
            // Counter Glyph
            value = CounterGlyph.SingletonValue;
            CounterGlyph actualCounter = target.GetGlyph<CounterGlyph>(value);
            Assert.IsNotNull(actualCounter);
            Assert.AreEqual(CounterGlyph.Name, actualCounter.TypeName);
            Assert.AreEqual(value, actualCounter.Value);
            // Number Glyph
            value = NumberGlyph.MaxValue.ToString();
            NumberGlyph actualNumber = target.GetGlyph<NumberGlyph>(value);
            Assert.IsNotNull(actualNumber);
            Assert.AreEqual(NumberGlyph.Name, actualNumber.TypeName);
            Assert.AreEqual(NumberGlyph.MaxValue, actualNumber.Value);
            // Object Glyph
            value = ObjectGlyph.SingletonValue;
            ObjectGlyph actualObject = target.GetGlyph<ObjectGlyph>(value);
            Assert.IsNotNull(actualObject);
            Assert.AreEqual(ObjectGlyph.Name, actualObject.TypeName);
            Assert.AreEqual(value, actualObject.Value);
            // Zero Glyph
            value = ZeroGlyph.SingletonValue;
            ZeroGlyph actualZero = target.GetGlyph<ZeroGlyph>(value);
            Assert.IsNotNull(actualZero);
            Assert.AreEqual(ZeroGlyph.Name, actualZero.TypeName);
            Assert.AreEqual(value, actualZero.Value);
        }

        /// <summary>
        ///Тест для GetGlyph
        ///</summary>
        [TestMethod()]
        public void GetGlyphTest1()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            // Direction Glyph
            Type glyphType = typeof(DirectionGlyph);
            string value = DirectionType.Right.ToString();
            Glyph actual;
            actual = target.GetGlyph(glyphType, value);
            Assert.AreEqual(DirectionGlyph.Name, actual.TypeName);
            Assert.AreEqual(DirectionType.Right.ToString(), actual.Value);
            Assert.IsInstanceOfType(actual, typeof(DirectionGlyph));
            Assert.AreEqual(DirectionType.Right, ((DirectionGlyph)actual).Value);
            // Chain Glyph
            glyphType = typeof(ChainGlyph);
            value = "C";
            actual = target.GetGlyph(glyphType, value);
            Assert.AreEqual(ChainGlyph.Name, actual.TypeName);
            Assert.AreEqual(value, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(ChainGlyph));
            // Counter Glyph
            glyphType = typeof(CounterGlyph);
            value = CounterGlyph.SingletonValue;
            actual = target.GetGlyph(glyphType, value);
            Assert.AreEqual(CounterGlyph.Name, actual.TypeName);
            Assert.AreEqual(CounterGlyph.SingletonValue, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(CounterGlyph));
            // Number Glyph
            glyphType = typeof(NumberGlyph);
            value = NumberGlyph.MinValue.ToString();
            actual = target.GetGlyph(glyphType, value);
            Assert.AreEqual(NumberGlyph.Name, actual.TypeName);
            Assert.AreEqual(NumberGlyph.MinValue.ToString(), actual.Value);
            Assert.IsInstanceOfType(actual, typeof(NumberGlyph));
            Assert.AreEqual(NumberGlyph.MinValue, ((NumberGlyph)actual).Value);
            // Object Glyph
            glyphType = typeof(ObjectGlyph);
            value = ObjectGlyph.SingletonValue;
            actual = target.GetGlyph(glyphType, value);
            Assert.AreEqual(ObjectGlyph.Name, actual.TypeName);
            Assert.AreEqual(ObjectGlyph.SingletonValue, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(ObjectGlyph));
            // Zero Glyph
            glyphType = typeof(ZeroGlyph);
            value = ZeroGlyph.SingletonValue;
            actual = target.GetGlyph(glyphType, value);
            Assert.AreEqual(ZeroGlyph.Name, value);
            Assert.AreEqual(ZeroGlyph.SingletonValue, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(ZeroGlyph));
        }

        /// <summary>
        ///Тест для GetGlyph
        ///</summary>
        [TestMethod()]
        public void GetGlyphTest2()
        {
            bool registerDefaultContainers = false;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            bool registerResult = target.RegisterDefaultContainers();
            Assert.IsTrue(registerResult);
            // Direction Glyph
            string glyphTypeName = DirectionGlyph.Name;
            string value = DirectionType.Forward.ToString();
            Glyph actual;
            actual = target.GetGlyph(glyphTypeName, value);
            Assert.AreEqual(DirectionGlyph.Name, actual.TypeName);
            Assert.AreEqual(DirectionType.Forward.ToString(), actual.Value);
            Assert.IsInstanceOfType(actual, typeof(DirectionGlyph));
            Assert.AreEqual(DirectionType.Forward, ((DirectionGlyph)actual).Value);
            // Chain Glyph
            glyphTypeName = ChainGlyph.Name;
            value = "A";
            actual = target.GetGlyph(glyphTypeName, value);
            Assert.AreEqual(ChainGlyph.Name, actual.TypeName);
            Assert.AreEqual("A", actual.Value);
            Assert.IsInstanceOfType(actual, typeof(ChainGlyph));
            // Counter Glyph
            glyphTypeName = CounterGlyph.Name;
            value = CounterGlyph.SingletonValue;
            actual = target.GetGlyph(glyphTypeName, value);
            Assert.AreEqual(CounterGlyph.Name, actual.TypeName);
            Assert.AreEqual(CounterGlyph.SingletonValue, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(CounterGlyph));
            // Number Glyph
            glyphTypeName = NumberGlyph.Name;
            value = 2.ToString();
            actual = target.GetGlyph(glyphTypeName, value);
            Assert.AreEqual(NumberGlyph.Name, actual.TypeName);
            Assert.AreEqual(value, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(NumberGlyph));
            Assert.AreEqual(2, ((NumberGlyph)actual).Value);
            // Object Glyph
            glyphTypeName = ObjectGlyph.Name;
            value = ObjectGlyph.SingletonValue;
            actual = target.GetGlyph(glyphTypeName, value);
            Assert.AreEqual(ObjectGlyph.Name, actual.TypeName);
            Assert.AreEqual(ObjectGlyph.SingletonValue, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(ObjectGlyph));
            // Zero Glyph
            glyphTypeName = ZeroGlyph.Name;
            value = ZeroGlyph.SingletonValue;
            actual = target.GetGlyph(glyphTypeName, value);
            Assert.AreEqual(ZeroGlyph.Name, actual.TypeName);
            Assert.AreEqual(ZeroGlyph.SingletonValue, actual.Value);
            Assert.IsInstanceOfType(actual, typeof(ZeroGlyph));
        }

        /// <summary>
        ///Тест для GetSingletonGlyph
        ///</summary>
        [TestMethod()]
        public void GetSingletonGlyphTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            // Counter Glyph
            Type glyphType = typeof(CounterGlyph);
            Glyph expected = target.GetGlyph(glyphType, CounterGlyph.SingletonValue);
            Assert.IsInstanceOfType(expected, typeof(CounterGlyph));
            Glyph actual;
            actual = target.GetSingletonGlyph(glyphType);
            Assert.AreEqual(expected.TypeName, actual.TypeName);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected, actual);
            Assert.IsInstanceOfType(actual, typeof(CounterGlyph));
            // Object Glyph
            glyphType = typeof(ObjectGlyph);
            expected = target.GetGlyph(glyphType, ObjectGlyph.SingletonValue);
            Assert.IsInstanceOfType(expected, typeof(ObjectGlyph));
            actual = target.GetSingletonGlyph(glyphType);
            Assert.AreEqual(expected.TypeName, actual.TypeName);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected, actual);
            Assert.IsInstanceOfType(actual, typeof(ObjectGlyph));
            // Zero Glyph
            glyphType = typeof(ZeroGlyph);
            expected = target.GetGlyph(glyphType, ZeroGlyph.SingletonValue);
            Assert.IsInstanceOfType(expected, typeof(ZeroGlyph));
            actual = target.GetSingletonGlyph(glyphType);
            Assert.AreEqual(expected.TypeName, actual.TypeName);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected, actual);
            Assert.IsInstanceOfType(actual, typeof(ZeroGlyph));
        }

        [TestMethod()]
        public void GetSingletonGlyphTest1()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            // Counter Glyph
            CounterGlyph expectedCounter;
            expectedCounter = target.GetGlyph<CounterGlyph>(CounterGlyph.SingletonValue);
            CounterGlyph actualCounter = target.GetSingletonGlyph<CounterGlyph>();
            Assert.AreEqual(expectedCounter.TypeName, actualCounter.TypeName);
            Assert.AreEqual(expectedCounter.Value, actualCounter.Value);
            Assert.AreEqual(expectedCounter, actualCounter);
            // Object Glyph
            ObjectGlyph expectedObject;
            expectedObject = target.GetGlyph<ObjectGlyph>(ObjectGlyph.SingletonValue);
            ObjectGlyph actualObject = target.GetSingletonGlyph<ObjectGlyph>();
            Assert.AreEqual(expectedObject.TypeName, actualObject.TypeName);
            Assert.AreEqual(expectedObject.Value, actualObject.Value);
            Assert.AreEqual(expectedObject, actualObject);
            // Zero Glyph
            ZeroGlyph expectedZero;
            expectedZero = target.GetGlyph<ZeroGlyph>(ZeroGlyph.SingletonValue);
            ZeroGlyph actualZero = target.GetSingletonGlyph<ZeroGlyph>();
            Assert.AreEqual(expectedZero.TypeName, actualZero.TypeName);
            Assert.AreEqual(expectedZero.Value, actualZero.Value);
            Assert.AreEqual(expectedZero, actualZero);
        }

        /// <summary>
        ///Тест для GetSingletonGlyph
        ///</summary>
        [TestMethod()]
        public void GetSingletonGlyphTest2()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            // Counter Glyph
            string glyphTypeName = CounterGlyph.Name;
            Glyph expected = target.GetGlyph<CounterGlyph>(CounterGlyph.SingletonValue);
            Assert.IsInstanceOfType(expected, typeof(CounterGlyph));
            Glyph actual;
            actual = target.GetSingletonGlyph(glyphTypeName);
            Assert.IsInstanceOfType(actual, typeof(CounterGlyph));
            Assert.AreEqual(expected, actual);
            // Object Glyph
            glyphTypeName = ObjectGlyph.Name;
            expected = target.GetGlyph<ObjectGlyph>(ObjectGlyph.SingletonValue);
            Assert.IsInstanceOfType(expected, typeof(ObjectGlyph));
            actual = target.GetSingletonGlyph(glyphTypeName);
            Assert.IsInstanceOfType(actual, typeof(ObjectGlyph));
            Assert.AreEqual(expected, actual);
            // Zero Glyph
            glyphTypeName = ZeroGlyph.Name;
            expected = target.GetGlyph<ZeroGlyph>(ZeroGlyph.SingletonValue);
            Assert.IsInstanceOfType(expected, typeof(ZeroGlyph));
            actual = target.GetSingletonGlyph(glyphTypeName);
            Assert.IsInstanceOfType(actual, typeof(ZeroGlyph));
            Assert.AreEqual(expected, actual);
        }

        #region TestGlyphContainer Methods

        private class TestGlyph :
            Glyph
        {
            public const string Name = "Test";

            public TestGlyph(string name)
                : base(TestGlyph.Name, name)
            { }
        }

        private class TestGlyphContainer :
            GlyphContainer<TestGlyph>
        {
            public TestGlyphContainer()
                : base(glyphIsSingleton: false)
            {
                foreach (string testName in new string[] { "T1", "T2" })
                {
                    TestGlyph glyph = new TestGlyph(testName);
                    this.AddGlyph(glyph);
                }
            }

            public override string GlyphTypeName
            {
                get { return TestGlyph.Name; }
            }
        }

        #endregion

        /// <summary>
        ///Тест для RegisterContainer
        ///</summary>
        [TestMethod()]
        public void RegisterContainerTest()
        {
            bool registerDefaultContainers = false;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            IGlyphContainer glyphContainer = new TestGlyphContainer();
            target.RegisterContainer(glyphContainer);
            Assert.IsTrue(target.ContainsContainer(glyphContainer));
            TestGlyph glyph = target.GetGlyph<TestGlyph>("T1");
            Assert.IsNotNull(glyph);
            Assert.AreEqual(TestGlyph.Name, glyph.TypeName);
            Assert.AreEqual("T1", glyph.Value);
            glyph = (TestGlyph)target.GetGlyph(TestGlyph.Name, "T2");
            Assert.IsNotNull(glyph);
            Assert.AreEqual(TestGlyph.Name, glyph.TypeName);
            Assert.AreEqual("T2", glyph.Value);
        }

        /// <summary>
        ///Тест для RegisterDefaultContainers
        ///</summary>
        [TestMethod()]
        public void RegisterDefaultContainersTest()
        {
            bool registerDefaultContainers = false;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            Assert.IsFalse(target.ContainsTypeName(DirectionGlyph.Name));
            Assert.IsFalse(target.ContainsTypeName(ChainGlyph.Name));
            Assert.IsFalse(target.ContainsTypeName(CounterGlyph.Name));
            Assert.IsFalse(target.ContainsTypeName(NumberGlyph.Name));
            Assert.IsFalse(target.ContainsTypeName(ObjectGlyph.Name));
            Assert.IsFalse(target.ContainsTypeName(ZeroGlyph.Name));
            bool expected = true;
            bool actual;
            actual = target.RegisterDefaultContainers();
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(target.ContainsTypeName(DirectionGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(ChainGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(CounterGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(NumberGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(ObjectGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(ZeroGlyph.Name));
            expected = false;
            actual = target.RegisterDefaultContainers();
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(target.ContainsTypeName(DirectionGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(ChainGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(CounterGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(NumberGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(ObjectGlyph.Name));
            Assert.IsTrue(target.ContainsTypeName(ZeroGlyph.Name));
            registerDefaultContainers = false;
        }

        [TestMethod()]
        public void TryRegisterContainerTest()
        {
            bool registerDefaultContainers = false;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            bool expected = true;
            bool actual;
            actual = target.TryRegisterContainer<TestGlyphContainer>();
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(target.ContainsType(typeof(TestGlyph)));
            TestGlyph glyph = target.GetGlyph<TestGlyph>("T1");
            Assert.IsNotNull(glyph);
            expected = false;
            actual = target.TryRegisterContainer<TestGlyphContainer>();
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(target.ContainsType(typeof(TestGlyph)));
            glyph = target.GetGlyph<TestGlyph>("T1");
            Assert.IsNotNull(glyph);
        }

        [TestMethod()]
        public void TryRegisterContainerTest1()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            Func<TestGlyphContainer> glyphContainerFactory;
            glyphContainerFactory = () => new TestGlyphContainer();
            bool expected = true;
            bool actual;
            actual = target.TryRegisterContainer<TestGlyphContainer>(glyphContainerFactory);
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(target.ContainsType(typeof(TestGlyph)));
            TestGlyph glyph = target.GetGlyph<TestGlyph>("T2");
            Assert.IsNotNull(glyph);
            expected = false;
            actual = target.TryRegisterContainer<TestGlyphContainer>(glyphContainerFactory);
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(target.ContainsType(typeof(TestGlyph)));
            glyph = target.GetGlyph<TestGlyph>("T2");
            Assert.IsNotNull(glyph);
        }

        /// <summary>
        ///Тест для UnregisterContainer
        ///</summary>
        [TestMethod()]
        public void UnregisterContainerTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            IGlyphContainer glyphContainer = new TestGlyphContainer();
            target.RegisterContainer(glyphContainer);
            Assert.IsTrue(target.ContainsType(typeof(TestGlyph)));
            TestGlyph glyph = target.GetGlyph<TestGlyph>("T1");
            Assert.IsNotNull(glyph);
            target.UnregisterContainer(glyphContainer);
            Assert.IsFalse(target.ContainsType(typeof(TestGlyph)));
            target.RegisterContainer(glyphContainer);
            Assert.IsTrue(target.ContainsType(typeof(TestGlyph)));
            glyph = target.GetGlyph<TestGlyph>("T1");
            Assert.IsNotNull(glyph);
        }

        /// <summary>
        ///Тест для GlyphTypeCount
        ///</summary>
        [TestMethod()]
        public void GlyphTypeCountTest()
        {
            bool registerDefaultContainers = false;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            int actual;
            actual = target.GlyphTypeCount;
            Assert.AreEqual(0, actual);
            target.RegisterDefaultContainers();
            actual = target.GlyphTypeCount;
            Assert.AreEqual(6, actual);
        }

        /// <summary>
        ///Тест для Item
        ///</summary>
        [TestMethod()]
        public void ItemTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            bool registerResult = target.TryRegisterContainer<TestGlyphContainer>();
            Assert.IsTrue(registerResult);
            string glyphTypeName = TestGlyph.Name;
            IGlyphContainer actual;
            actual = target[glyphTypeName];
            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(TestGlyph), actual.GlyphType);
            Assert.AreEqual(TestGlyph.Name, actual.GlyphTypeName);
            Assert.IsFalse(actual.GlyphIsSingleton);
            Assert.IsTrue(actual.ValueIsAllowed("T1"));
            Assert.IsTrue(actual.ValueIsAllowed("T2"));
            Assert.IsFalse(actual.ValueIsAllowed("T3"));
        }

        /// <summary>
        ///Тест для Item
        ///</summary>
        [TestMethod()]
        public void ItemTest1()
        {
            bool registerDefaultContainers = false;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            bool registerResult = target.TryRegisterContainer<TestGlyphContainer>();
            Assert.IsTrue(registerResult);
            Type glyphType = typeof(TestGlyph);
            IGlyphContainer actual;
            actual = target[glyphType];
            Assert.IsNotNull(actual);
            Assert.AreEqual(typeof(TestGlyph), actual.GlyphType);
            Assert.AreEqual(TestGlyph.Name, actual.GlyphTypeName);
            Assert.IsFalse(actual.GlyphIsSingleton);
            Assert.IsTrue(actual.ValueIsAllowed("T1"));
            Assert.IsTrue(actual.ValueIsAllowed("T2"));
            Assert.IsFalse(actual.ValueIsAllowed("T3"));
        }

        /// <summary>
        ///Тест для GetAllowedGlyphTypeNames
        ///</summary>
        [TestMethod()]
        public void GetAllowedGlyphTypeNamesTest()
        {
            bool registerDefaultContainers = true;
            GlyphPool target = new GlyphPool(registerDefaultContainers);
            IList<string> expected = new string[]
            {
                DirectionGlyph.Name,
                NumberGlyph.Name, 
                ChainGlyph.Name, 
                ObjectGlyph.Name, 
                ZeroGlyph.Name,
                CounterGlyph.Name 
            };
            IList<string> actual;
            actual = target.GetAllowedGlyphTypeNames();
            Assert.AreEqual(expected.Count, actual.Count);
            foreach (string expectedItem in expected)
            {
                Assert.IsTrue(actual.Contains(expectedItem));
            }
        }
    }
}
